//
//  SafeThreePeopleCell.m
//  Estate
//
//  Created by wangdongdong on 2017/10/9.
//  Copyright © 2017年 ttsx. All rights reserved.
//

#import "SafeThreePeopleCell.h"
@interface SafeThreePeopleCell()
@property (nonatomic,assign) BOOL isEdit;

@end
@implementation SafeThreePeopleCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.isEdit = YES;

    
    self.nameLabel.textColor = mainTitleColor;
    self.titleLabel.textColor = mainTitleColor;
    self.otherLabel.textColor = subtitleColor;
    
    // 到岗状态
    [self.state addTarget:self action:@selector(changeState:) forControlEvents:UIControlEventTouchUpInside];
    [self.state mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(50*BIZ);
    }];
    self.state.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.state setImage:[UIImage imageNamed:@"notArrive"] forState:UIControlStateNormal];
    [self.state setTitleColor:UIColorFromRGB(0xed475e) forState:UIControlStateNormal];
    [self.state setTitle:@"未到岗" forState:UIControlStateNormal];
    
    
    [self.state setTitleColor:UIColorFromRGB(0x45de89) forState:UIControlStateSelected];
    [self.state setTitle:@"已到岗" forState:UIControlStateSelected];
    [self.state setImage:[UIImage imageNamed:@"havePost"] forState:UIControlStateSelected];
    
    // 调整button图文位置
    self.state.imageEdgeInsets = UIEdgeInsetsMake(-10, 0, 10, 0);
    self.state.titleEdgeInsets = UIEdgeInsetsMake(40, -70, -40, 0);

    self.certificateInspectionLabel.textColor = mainTitleColor;
    self.certificateValidLabel.textColor = mainTitleColor;
    self.appraiseLabel.textColor = mainTitleColor;
    
    // 职务
    self.positionLabel.backgroundColor = UIColorFromRGB(0x6ed5ff);
    self.positionLabel.layer.cornerRadius = 7.5;
    self.positionLabel.layer.masksToBounds = YES;
    
    // 其他说明
    self.otherText.layer.borderColor = [[UIColor colorWithRed:215.0 / 255.0 green:215.0 / 255.0 blue:215.0 / 255.0 alpha:1] CGColor];
    self.otherText.layer.borderWidth = 0.6f;
    self.otherText.layer.cornerRadius = 6.0f;
    self.otherText.delegate = self;
    
    // 证书是否查验
    [self.certificateInspectionSwitch addTarget:self action:@selector(certificateInspection:) forControlEvents:UIControlEventValueChanged];
    // 证书是否有效
    [self.certificateValidSwitch addTarget:self action:@selector(certificateValid:) forControlEvents:UIControlEventValueChanged];
    // 评价
    [self.appraiseSwitch addTarget:self action:@selector(appraise:) forControlEvents:UIControlEventValueChanged];
}

// 不可编辑
- (void)isNoEdit {
    self.isEdit = NO;

    self.certificateInspectionSwitch.enabled = NO;
    self.certificateValidSwitch.enabled = NO;
    self.appraiseSwitch.enabled = NO;
    self.otherText.editable = NO;
}

// 证书是否查验
- (void)certificateInspection:(UISwitch *)switchButton {
    BOOL isButtonOn = [switchButton isOn];
    if (isButtonOn) {
        
        if (self.certificateInspectionBlock) {
            self.certificateInspectionBlock(@"1");
        }
    } else {
        if (self.certificateInspectionBlock) {
            self.certificateInspectionBlock(@"0");
        }
    }
}

// 证书是否有效
- (void)certificateValid:(UISwitch *)switchButton {
    BOOL isButtonOn = [switchButton isOn];
    if (isButtonOn) {
        
        if (self.certificateValidBlock) {
            self.certificateValidBlock(@"1");
        }
    } else {
        if (self.certificateValidBlock) {
            self.certificateValidBlock(@"0");
        }
    }
}

// 评价
- (void)appraise:(UISwitch *)switchButton {
    BOOL isButtonOn = [switchButton isOn];
    if (isButtonOn) {
        
        if (self.appraiseBlock) {
            self.appraiseBlock(@"1");
        }
    } else {
        if (self.appraiseBlock) {
            self.appraiseBlock(@"0");
        }
    }
}

#pragma mark UITextFieldDelegate(其他说明)
- (void)textViewDidChange:(UITextView *)textView {
    if (self.otherTextBlock) {
        self.otherTextBlock(textView.text);
    }
}
// 改变状态
- (void)changeState:(UIButton *)btn {
    if (!self.isEdit) {
        return;
    }
    btn.selected = !btn.selected;
    if (btn.selected) {
        // 回调数据
        if (self.stateBlock) {
            self.stateBlock(@"1");
        }
    } else {
       // 回调数据
        if (self.stateBlock) {
            self.stateBlock(@"0");
        }
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


@end

